
#include "common.h"

#define LED_GRP GPIOD
#define LED_PIN GPIO_Pin_4

void led_init()
{
    GPIO_Init(LED_GRP, LED_PIN, GPIO_Mode_Out_PP_Low_Fast);
    GPIO_ResetBits(LED_GRP, LED_PIN);
}

void led_open()
{
    GPIO_SetBits(LED_GRP, LED_PIN);
    printf("%s\r\n", __FUNCTION__);
}

void led_close()
{
    GPIO_ResetBits(LED_GRP, LED_PIN);
    printf("%s\r\n", __FUNCTION__);
}

void led_selftest()
{
    GPIO_ToggleBits(LED_GRP, LED_PIN);
}

static uint8_t led_flag = 0;
void led_set_mode(uint8_t mode)
{
    led_flag = mode;
    set_timer_event(LED_TASK, EVENT_LED_TIMER, 30);
}

int led_callback(int value)
{
    if (value & EVENT_LED_START)
    {
        //set_timer_event(LED_TASK, EVENT_LED_TIMER, 100);
        value &= ~(EVENT_LED_START);
    }
  
    if (value & EVENT_LED_TIMER)
    {
        if (led_flag == 0x1)
        {
            led_selftest();
            set_timer_event(LED_TASK, EVENT_LED_TIMER, 500);
            printf("shansuo\r\n");
        }
        else if (led_flag == 0x2)
        {
            led_open();
        }
        else
        {
            led_close();
        }
    }
    return value;
}
